package com.neu.credit.creditscore.common.utils;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.Instant;

public class UnixTimestampDeserializer extends JsonDeserializer<Instant> {
    @Override
    public Instant deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
        double timestamp = p.getDoubleValue();
        long seconds = (long) timestamp;
        int nanos = (int) ((timestamp - seconds) * 1_000_000_000);
        return Instant.ofEpochSecond(seconds, nanos);
    }


}